import { Injectable, NestMiddleware } from '@nestjs/common';
import { NextFunction, Request, Response } from 'express';

@Injectable()
export class TmpMiddleware implements NestMiddleware {
  async use(req: Request, res: Response, next: NextFunction) {
    console.log('微信来消息了', req.originalUrl);
    next();
    // const isXMLType = req.headers['content-type'] === 'text/xml';
    // if (isXMLType) {
    //   let data = Buffer.from('');
    //   req.on('data', (chunk) => {
    //     data = Buffer.concat([data, chunk]);
    //   });
    //   req.on('end', () => {
    //     req.body = data;
    //     next();
    //     console.log(req.method, req.originalUrl);
    //   });
    //   req.on('error', (e) => {
    //     next(e);
    //   });
    // }
  }
}
